package com.csaba.connector.otp.model;

import java.util.logging.Level;

import org.apache.http.impl.client.DefaultHttpClient;

import com.csaba.connector.ServiceException;
import com.csaba.connector.otp.parser.OTPCodes;
import com.csaba.connector.web.util.SpecialHttpClient;
import com.csaba.connector.web.util.WebSession;
import com.csaba.util.LoggerHelper;

public class OTPSession extends WebSession
{
	private static final long serialVersionUID = 5638994273784397711L;

	public final static boolean DUMP_TEXT = false;
	public final static boolean DEBUG_FILE = true;
	public final static boolean DEBUG_COOKIES = true;
	public final static String DEBUG_FILE_PATH = "../otp.source/";

	private int operationCounter = 1;

	public OTPSession()
	{
		super();

		preferredEncoding = OTPCodes.HTML_CHARSET;

		setBank(OTPBank.getInstance());
		setForceCookieSession(true);
		if ( DEBUG_FILE )
			setDebugFilePath(DEBUG_FILE_PATH);
		setDumpText(DUMP_TEXT);
		setDebugCookies(DEBUG_COOKIES);
	}

	@Override
	protected DefaultHttpClient initHttpClient()
	{
		return new SpecialHttpClient(SpecialHttpClient.CERT_OTP);
	}

	public int getOperationCounter()
	{
		return operationCounter++;
	}

	public static void main( final String[] args ) throws ServiceException
	{
		//init logger
		LoggerHelper.initLogger(Level.ALL);

		final OTPSession session = new OTPSession();

		session.doGet("https://www.otpbank.hu/portal/hu/OTPdirektbelepes");
		session.doGet("https://www.otpbankdirekt.hu/");
		session.doGet("https://www.otpbankdirekt.hu/homebank/do/bejelentkezes");
	}
}